package com.wu.consumer;

import com.rabbitmq.client.Channel;
import com.wu.config.ConfirmConfig;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.nio.charset.StandardCharsets;

/**
 * @program: RabbitMQ-Study
 * @author: 吴磊
 * @create: 2021-12-19 21:16
 * 确认接收消息
 */
@Component
@Slf4j
public class ConfirmConsumer {

    /**
     * 接收正常消息
     *
     * @param message
     * @param channel
     */
    @RabbitListener(queues = ConfirmConfig.CONFIRM_QUEUE_NAME)
    public void receiveConfirmMessage(Message message, Channel channel) {
        log.info("接收消息：{}", new String(message.getBody(), StandardCharsets.UTF_8));
    }

    /**
     * 接收报警消息
     *
     * @param message
     * @param channel
     */
    @RabbitListener(queues = ConfirmConfig.WARNING_QUEUE_NAME)
    public void receiveWarningMessage(Message message, Channel channel) {
        log.warn("警告发现不可路由消息：{}", new String(message.getBody(), StandardCharsets.UTF_8));
    }

}
